#!/bin/bash

      #///////////////////////////////////////////////////////
      #
      #   Betsu-Install v0.0.1 for the Betsu Project
      #   Copyright (C) 2022 Alexa Hattori <unixcat@anche.no>
      #   SPDX-License-Identifier: GPL-3.0-only
      #   <https://gnu.org/license/gpl-3.0.html>
      #
      #///////////////////////////////////////////////////////

main_menu () {
    clear

    echo "welcome to the
 _            _               
| |__    ___ | |_  ___  _   _ 
| '_ \  / _ \| __|/ __|| | | |
| |_) ||  __/| |_ \__ \| |_| |
|_.__/  \___| \__||___/ \__,_|

Betsu-Install v0.0.1                             
"    
    select menu in "Betsu-Banner" "Betsu-Helper" "Exit"; do
	case $menu in
	    "Betsu-Banner" ) betsu_banner_menu; break;;
	    "Betsu-Helper" ) betsu_helper_menu; break;;
	    "Exit" ) echo "Exiting, bye!"; break;;
	esac
    done
}

betsu_directory () {
    if [ -d "/usr/betsu/bin" ]; then
	echo "0" > /dev/null
    else
	echo "[ INFO ] Betsu-Install | Directory '/usr/betsu/bin' doesn't exists, creating..."
	mkdir -p -v /usr/betsu/bin
    fi
} 

#///////////////////////
#  Betsu-Banner Zone   # 
#/////////////////////// 

betsu_banner_menu () {
    echo "What do you want to do?"
    select banner_menu in "Install Betsu-Banner" "Uninstall Betsu-Banner" "Main Menu"; do
	case $banner_menu in
	    "Install Betsu-Banner" ) betsu_banner_install; break;;
	    "Uninstall Betsu-Banner" ) betsu_banner_uninstall; break;;
	    "Main Menu" ) main_menu; break;;
	esac
    done
}

betsu_banner_install () {
    clear

    echo "
 _            _               
| |__    ___ | |_  ___  _   _ 
| '_ \  / _ \| __|/ __|| | | |
| |_) ||  __/| |_ \__ \| |_| |
|_.__/  \___| \__||___/ \__,_|

Betsu-Install v0.0.1

Do you want to install Betsu-Banner?                             
"
    
    select ic in "Install" "Cancel"; do
	case $ic in
	    "Install" ) break;;
	    "Cancel" ) clear; main_menu; break;;
	esac
    done
    echo ""
    echo "[ INFO ] Betsu-Install | Fetching latest Betsu-Banner..."
    pushd /tmp
    curl https://notabug.org/Betsu/Betsu-Scripts/raw/master/betsu-banner/betsu-banner.sh > betsu-banner
    betsu_directory
    sudo mv betsu-banner /usr/betsu/bin/betsu-banner
    sudo chmod a+x /usr/betsu/bin/betsu-banner
    popd
    export PATH=$PATH:/usr/betsu/bin
    echo "export PATH=$PATH:/usr/betsu/bin" >> ~/.bashrc
    echo "[ INFO ] Betsu-Install | betsu-banner --generate-config"
    betsu-banner --generate-config
    echo ""
    echo "#########################"
    echo "Betsu-Banner is Installed"
    echo "#########################"
    echo "- Please, add '/usr/betsu/bin' to your PATH."
    echo "- It's already added to your .bashrc, if you use bash, just restart your shell."
    echo "Thank you, for choosing Betsu!" 
}
					   

betsu_banner_uninstall () {
    echo "Are you sure you want to uninstall Betsu-Banner?"
    select yn in "Yes" "No"; do
	case $yn in
	    "Yes" ) break;;
	    "No" ) exit;;
	esac
    done

    echo "[ INFO ] Betsu-Install | Uninstalling Betsu-Banner..."
    sudo rm -rfv /usr/betsu/bin
    sudo rm -rfv /home/*/.config/betsu
    echo "##################################"
    echo "Betsu-Banner has been uninstalled."
    echo "##################################"
}

#///////////////////////                                                                                                          
#  Betsu-Helper Zone   #         
#///////////////////////

betsu_helper_menu () {
    echo "Is not Available Yet."
}


clear
main_menu
